1 // TODO code-sharing between scales 2 3 /** 4 * @ignore 5 * @class 6 */ 7 pv.Scale = function() {}; 8 9 /** 10 * @private Returns a function that interpolators from the start value to the 11 * end value, given a parameter <i>t</i> in [0, 1]. 12 * 13 * @param start the start value. 14 * @param end the end value. 15 */ 16 pv.Scale.interpolator = function(start, end) { 17 if (typeof start == "number") { 18 return function(t) { 19 return t * (end - start) + start; 20 }; 21 } 22 23 /* For now, assume color. */ 24 start = pv.color(start).rgb(); 25 end = pv.color(end).rgb(); 26 return function(t) { 27 var a = start.a * (1 - t) + end.a * t; 28 if (a < 1e-5) a = 0; // avoid scientific notation 29 return (start.a == 0) ? pv.rgb(end.r, end.g, end.b, a) 30 : ((end.a == 0) ? pv.rgb(start.r, start.g, start.b, a) 31 : pv.rgb( 32 Math.round(start.r * (1 - t) + end.r * t), 33 Math.round(start.g * (1 - t) + end.g * t), 34 Math.round(start.b * (1 - t) + end.b * t), a)); 35 }; 36 }; 37